/*
 * Created by Federico Pisarello - SisDev Software (c) 2012 - fpisarello@sisdevsoft.com
 */

var actionForm = 'campeonatosAction.php';

var oTableAP;
var oTableP;
var oTableA;
var oTableM;
var oTablePE;

function $_init()
{
	$('#btnCampeonatos').removeClass('btnMenu').addClass('btnMenuAct');
	
	$_initTableAP();
	$_initTableP();
	$_initTableA();
	$_initTableM();
		
	//Add Click for All Buttons in Search Form
	$("#btnAnilloPlata").click( function(e) {
		$('#pichon').hide();
		$('#adulto').hide();
		$('#mixto').hide();
		$('#anilloPlata').fadeIn();
    });
	
	$("#btnPichon").click( function(e) {
		$('#anilloPlata').hide();
		$('#adulto').hide();
		$('#mixto').hide();
		$('#pichon').fadeIn();
    });

	$("#btnAdulto").click( function(e) {
		$('#anilloPlata').hide();
		$('#pichon').hide();
		$('#mixto').hide();
		$('#adulto').fadeIn();
    });
	
	$("#btnMixto").click( function(e) {
		$('#anilloPlata').hide();
		$('#pichon').hide();
		$('#adulto').hide();
		$('#mixto').fadeIn();
    });
	
	$('#btnSearchPichon').click( function(e) {
		oTableP.fnDraw();
    });
	$('#btnSearchAdulto').click( function(e) {
		oTableA.fnDraw();
    });
	$('#btnSearchMixto').click( function(e) {
		oTableM.fnDraw();
    });
}

function $_initTableM()
{
	$(document).ready(function() {
		oTableM = $('#dt_mixto').dataTable( {
					"bJQueryUI": true,
					"sPaginationType": "two_button",
					"bInfo": false,
					"bLengthChange": false,
					"bProcessing": true,
					"bServerSide": true,
					"sAjaxSource": "campeonatosAction.php" + "?actionOfForm=searchCarrerasMixto",
					"fnServerData": function(sSource, aoData, fnCallback)
								    {
							          aoData.push( { "name": "min_pos", "value": $( "#min_posMixto" ).val() },
							                       { "name": "max_pos", "value": $( "#max_posMixto" ).val() } );
							          $.getJSON( sSource, aoData, function (json) { 
											fnCallback(json)
										}); 
								    },
					"aoColumns": [
					  			null,
					  			null,
					  			null,
					  			null,
					  			null,
					  			null,
					  			null
					  		]

				}).rowGrouping({
					iGroupingColumnIndex: 0,
					iGroupingColumnIndex2: 1
			});
		$('#dt_mixto').removeAttr('style');
	});
}

function $_initTableA()
{
	$(document).ready(function() {
		oTableA = $('#dt_adulto').dataTable( {
					"bJQueryUI": true,
					"sPaginationType": "two_button",
					"bInfo": false,
					"bLengthChange": false,
					"bProcessing": true,
					"bServerSide": true,
					"sAjaxSource": "campeonatosAction.php" + "?actionOfForm=searchCarrerasAdulto",
					"fnServerData": function(sSource, aoData, fnCallback)
								    {
							          aoData.push( { "name": "min_pos", "value": $( "#min_posAdulto" ).val() },
							                       { "name": "max_pos", "value": $( "#max_posAdulto" ).val() } );
							          $.getJSON( sSource, aoData, function (json) { 
											fnCallback(json)
										}); 
								    },
					"aoColumns": [
					  			null,
					  			null,
					  			null,
					  			null,
					  			null,
					  			null,
					  			null
					  		]

				}).rowGrouping({
					iGroupingColumnIndex: 0,
					iGroupingColumnIndex2: 1
			});
		$('#dt_adulto').removeAttr('style');
	});
}

function $_initTableP()
{
	$(document).ready(function() {
		oTableP = $('#dt_pichon').dataTable( {
					"bJQueryUI": true,
					"sPaginationType": "two_button",
					"bInfo": false,
					"bLengthChange": false,
					"bProcessing": true,
					"bServerSide": true,
					"sAjaxSource": "campeonatosAction.php" + "?actionOfForm=searchCarrerasPichon",
					"fnServerData": function(sSource, aoData, fnCallback)
								    {
							          aoData.push( { "name": "min_pos", "value": $( "#min_posPichon" ).val() },
							                       { "name": "max_pos", "value": $( "#max_posPichon" ).val() } );
							          $.getJSON( sSource, aoData, function (json) { 
											fnCallback(json)
										}); 
								    },
					"aoColumns": [
					  			null,
					  			null,
					  			null,
					  			null,
					  			null,
					  			null,
					  			null
					  		]

				}).rowGrouping({
					iGroupingColumnIndex: 0,
					iGroupingColumnIndex2: 1
			});
		$('#dt_pichon').removeAttr('style');
	});
}

function $_initTableAP()
{	
	$(document).ready(function() {
		oTableAP = $('#dt_campeonatos').dataTable( {
					"bJQueryUI": true,
					"sPaginationType": "two_button",
					"bInfo": false,
					"bLengthChange": false,
					"bProcessing": true,
					"bServerSide": true,
					"sAjaxSource": "campeonatosAction.php" + "?actionOfForm=searchCarrerasAnilloPlata",
					"aaSorting": [[2,'desc']],
					"aoColumns": [
					  			null,
					  			null,
					  			null
					  		]

				});
	});	
}
